home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 120 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.6 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: Robert DiFalco <difalco@primenet.com>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Enhanced container functionality
  5. Date: 20 Jan 1996 16:22:23 GMT
  6. Organization: Primenet Services for the Internet
  7. Sender: root@primenet.com
  8. Approved: clamage@eng.sun.com (comp.std.c++)
  9. Message-ID: <4dphil$k6n@nnrp1.news.primenet.com>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Content-Type: text
  12. X-Posted-By: ip087.lax.primenet.com
  13. Content-Length: 1939
  14. Originator: clamage@taumet
  15.  
  16. "Eugene Radchenko" <eugene@qsar.chem.msu.su> writes:
  17. > Hi!
  18. > Having used the STL for some time, I have come to greatly missing some nice
  19. > things (and eventually derived Vector<T> from vector<T>, adding them along
  20. > with persistence support).
  21. > First, it is the ability to (easily) flush the entire container
  22. >   void erase() { erase(begin(), end()); }
  23. > Second, it is the 'post-factum' equivalents to some constructors
  24. >   void assign(size_type n, T t = T());
  25. >   void assign(const_iterator first, const_iterator last);
  26. > etc. - putting the container into the same state as the one it would have
  27. > after the respective constructor (with the possible exception of more
  28. > reserved space available).
  29. > I think these features deserve inclusion.
  30.  
  31. I'd have to disagree. I've often found operations like Erase, 
  32. Clear, Assign and such as somewhat strange. Essentially, when
  33. you say "assign", you are saying give me a new container. If 
  34. this is the case, why not just create a new container? Same 
  35. with Erase. Why would you "erase" the entire contents of a 
  36. container if not to create a new one? Assigning or erasing
  37. specific items is different since then you are just changing
  38. the container rather than recreating it. The only reasons I
  39. can see for wanting Erase and Assign would be efficiency where
  40. one would rather erase all the items of the current container
  41. and assign new ones rather than to simply create a new 
  42. container. This seems semantically impure to me and I'd just
  43. instantiate a new one then resuse a current container that
  44. is no longer needed around. I would imagine the relative
  45. efficiency metrics between the two are about the same. You can
  46. even take this sort of thinking to things like ranges. Should
  47. one really be able to redefine the Upper or Lower bound of 
  48. a range? Probably not, ranges are small and you are probably
  49. just better of creating a new one. For example, check out
  50. the differece between "a" and "b" below:
  51.  
  52.  
  53.  
  54. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  55.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  56.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  57.  
  58.